<form method="post" enctype="multipart/form-data" target="_blank" id="form-order">
    <div class="table-responsive">
        <table class="table table-bordered table-hover">

                <thead>
                <tr>
                    <td style="width: 1px;" class="text-center">
                        <!--
                            <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
                        -->
                    </td>
                    <td class="text-right">
                        <a href="javascript:sort('goods_id');">ID</a>
                    </td>
                    <td class="text-left">
                        <a href="javascript:sort('goods_name');">商品名称</a>
                    </td>
                    <td class="text-left">
                        <a href="javascript:sort('goods_sn');">货号</a>
                    </td>
                    <td class="text-left">
                        <a href="javascript:sort('cat_id');">分类</a>
                    </td>
                    <td>
                        <a href="javascript:void(0);">商品类型</a>
                    </td>
                    <td class="text-left">
                        <a href="javascript:sort('shop_price');">价格</a>
                    </td>

                    <td class="text-left">
                        <a href="javascript:void(0);">库存（本店）</a>
                    </td>


                    <td class="text-center">
                        <a href="javascript:sort('is_on_sale');">上架（本店）</a>
                    </td>
                    <td class="text-left">
                        <a href="javascript:void(0);">库存（系统）</a>
                    </td>
                    <td class="text-center">
                        <a href="javascript:sort('is_on_sale');">上架（系统）</a>
                    </td>
                    <td class="text-center">
                        <a href="javascript:sort('is_recommend');">推荐</a>
                    </td>
                    <td class="text-center">
                        <a href="javascript:sort('is_new');">新品</a>
                    </td>
                    <td class="text-center">
                        <a href="javascript:sort('is_hot');">热卖</a>
                    </td>

                </tr>
                </thead>
                <tbody>
                <volist name="goodsList" id="list">
                    <tr>
                        <td class="text-center">
                            <!-- <input type="checkbox" name="selected[]" value="6">-->
                            <input type="hidden" name="shipping_code[]" value="flat.flat">
                        </td>
                        <td class="text-right">{$list.goods_id}</td>
                        <td class="text-left">{$list.goods_name|getSubstr=0,33}</td>
                        <td class="text-left">{$list.goods_sn}</td>
                        <td class="text-left">{$catList[$list[cat_id]][name]}</td>
                        <td calss="text-center">{:shop_goods_type($list['shop_goods_type'])}</td>
                        <td class="text-left">{$list.shop_price}</td>

                        <td>
                            <input type="text" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"
                                   onpaste="this.value=this.value.replace(/[^\d.]/g,'')"  onchange="changeShopStoreCount(this);"
                                   size="4"  data-id="{$list.goods_id}" data-on_sale="{$list[shop_on_sale]}" value="{$list.shop_store_count}" id="store_id_{$list.goods_id}"/>
                        </td>

                        <td class="text-center">
                            <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[shop_on_sale] eq 1'>yes.png<else />cancel.png</if>" onclick="changeGoodsOnSale('{$list.goods_id}', this)"/>
                        </td>

                        <td class="text-left">
                            {$list.store_count}
                        </td>
                        <td class="text-center">
                            <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[is_on_sale] eq 1'>yes.png<else />cancel.png</if>" onclick="javascript:alert('无权限操作！');"/>
                        </td>
                        <td class="text-center">
                            <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[is_recommend] eq 1'>yes.png<else />cancel.png</if>"  onclick="javascript:alert('无权限操作！');"/>
                        </td>
                        <td class="text-center">
                            <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[is_new] eq 1'>yes.png<else />cancel.png</if>"  onclick="javascript:alert('无权限操作！');"/>
                        </td>
                        <td class="text-center">
                            <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[is_hot] eq 1'>yes.png<else />cancel.png</if>"  onclick="javascript:alert('无权限操作！');"/>
                        </td>

                    </tr>
                </volist>
                </tbody>

        </table>
    </div>
</form>
<div class="row">
    <div class="col-sm-3 text-left"></div>
    <div class="col-sm-9 text-right">{$page}</div>
</div>
<script>
    // 点击分页触发的事件
    $(".pagination  a").click(function(){
        cur_page = $(this).data('p');
        ajax_get_table('search-form2',cur_page);
    });

    $(function () {
        $("[data-toggle='tooltip']").tooltip();
    })
    //修改库存
    function changeShopStoreCount(obj){
        var on_sale = $(obj).data('on_sale');
        if(on_sale == 0){
            layer.msg('商品未上架不能修改', {
                icon: 2,
                time: 1000
            });
            return;
        }
        var id = $(obj).data('id');
        var value = parseInt($(obj).val());
        if(value <= 0){
            layer.msg('库存数量为大于0的整数', {
                icon: 2,
                time: 1000
            });
            return;
        }
        $.ajax({
            url: "/index.php/admin/ShopGoods/updateStore",
            type: 'POST',
            dataType:'json',
            data: {
                goods_id: id,
                store_count: value,
                shop_id : $('#shop_id').val()
            },
            success: function (data) {
                if(data.status == 1){
                    layer.msg('修改成功', {
                        icon: 1,
                        time: 1000
                    });
                }else{
                    layer.msg(data.msg, {
                        icon: 2,
                        time: 1000
                    });
                }

            }
        });
    }
    //修改上架状态
    function changeGoodsOnSale(goods_id, obj){
        var src = "";
        if($(obj).attr('src').indexOf("cancel.png") > 0 )
        {
            src = '/Public/images/yes.png';
        }else{
            src = '/Public/images/cancel.png';
        }

        $.ajax({
            url:"/index.php?m=Admin&c=ShopGoods&a=updateOnSale&goods_id="+goods_id+"&shop_id="+$('#shop_id').val(),
            success: function(res){
                if(res.status == -1){
                    alert(res.msg);
                }else{
                    $(obj).attr('src',src);
                    var is_onsale = $("#store_id_"+goods_id).data('on_sale');
                    var update_onsale = is_onsale == 0 ? 1 : 0;
                    alert(update_onsale);
                    $("#store_id_"+goods_id).data('on_sale',update_onsale);

                }
            }
        });
    }
</script>